import React from 'react'
import { HashRouter, Redirect, Route, Switch } from 'react-router-dom'

import Box from '../views/box/Box'
import Login from '../views/login/Login'
export default function IndexRouter() {
    return (
        <HashRouter>
            
            <Switch>
                <Route path='/login' component={Login} />
                {/* 没有token就重定向到登录页 */}
                <Route path='/' render={() => {
                    return localStorage.getItem("token") ?
                        <Box /> :
                        <Redirect from='/' to='/login' />
                }} />
            </Switch>

        </HashRouter>
    )
}
